<?php
/**
 * Created By PhpStorm
 * Author: patrick wu
 * Date: 2020/9/19
 * Time: 16:24
 */
namespace App\Http\Model\Mysql;

use Illuminate\Database\Eloquent\Model;

class ShopModel extends Model
{
    const IS_LOCK   =   1,
          NOT_LOCK  =   0;

    const IS_OPEN   =   1,
          NOT_OPEN  =   0;

    const APPLY_INIT=   0,
          APPLY_YES =   1,
          APPLY_NO  =   2;

    const IS_DELETE =   1,
          NOT_DELETE=   0;

    protected $table    =   'mini_shop';

    protected $guarded  =   [];

    protected $dateFormat   =   'U';

    /**
     * 局部作用域，获取有效店铺
     * @param $query
     * @return mixed
     */
    public function scopeActive($query)
    {
        return $query->where(['is_open' => self::IS_OPEN, 'is_delete' => self::NOT_DELETE, 'is_lock' => self::NOT_LOCK, 'apply_status' => self::APPLY_YES]);
    }

    /**
     * 定义链接产品表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function product()
    {
        return $this->hasMany(ProductModel::class, 'shop_id', 'id');
    }

    /**
     * 定义链接品牌表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function brand()
    {
        return $this->hasMany(BrandModel::class, 'shop_id', 'id');
    }
}
